package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DBoc {

	public static Connection connection = null;
	public static Statement statement = null;
	
	public void Connect() {
//		if (connection != null) return;
		
		String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://127.0.0.1:3306/grade";
		String user = "root";
		String password = "123";

		try {
			Class.forName(driver);
			
			try {
				connection = DriverManager.getConnection(url, user, password);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
	public void Close() {
		if (statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
				System.out.print("closing statement failed");
				e.printStackTrace();
			} finally {
				if (connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						System.out.print("closing connection failed");
						e.printStackTrace();
					}
				}
			}
		}
	}

}
